var log = console.log;
var API = API || {};

var is_date_init = false;

API.Booking = {
    Init: function () {

        /***********************************************************
         * JQUERY UI Calendar
         ***********************************************************/
        API.Form.DatePicker.Init("#check_in", "#check_out", 1);


        $('#return_transfer').on('change', function () {

            var is_checked = $(this).is(":checked");

            $("#payment_insurance").mask(API.Data.lang['calculating'] + "...");

            function action_delay() {

                if (is_checked == true) {

                    $('.transfer-total-price').html(transfer_return_price);
                    $('.transfer-total-price-percent').html(R_30_PERCENT_RETURN);
                    $('#payment_insurance em').html(service_name_return);

                } else {
                    $('.transfer-total-price').html(transfer_price);
                    $('.transfer-total-price-percent').html(R_30_PERCENT);
                    $('#payment_insurance em').html(service_name);
                }



                $("#payment_insurance").unmask();
            }

            var randomnumber = 401 + Math.floor(Math.random() * 501);

            window.setTimeout(function () {
                action_delay();
            }, randomnumber);

            $.scrollTo('#payment_insurance', 500);

            if (is_checked == true) {
                $("#ret_transfer_controll").show();

                if (!is_date_init) {
                    is_date_init = true;
                    API.Form.DatePicker.Init("#check_in", "#check_out", 1);
                }

            } else {
                $("#ret_transfer_controll").hide();
            }


        });

        show_advanced_payment = function () {

            $("#payment_insurance").mask(API.Data.lang['calculating'] + "...");

            var value = $(this).val();

            function action_delay() {

                $.scrollTo('#payment_insurance', 500);

                if (value === '30% now and 70% balance upon arrival' || value === '30% now and 70% balance 10 days before arrival') {
                    $('.advance_payment').show();
                } else {
                    $('.advance_payment').hide();
                }

                $("#payment_insurance").unmask();
            }

            var randomnumber = 401 + Math.floor(Math.random() * 501);

            window.setTimeout(function () {
                action_delay();
            }, randomnumber);
//        return false;

        }

        $('input[name="payment_options"]').on('change', show_advanced_payment);

    }
};

$(function () {

    API.Booking.Init();

});